package com.herr.processor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.PriorityOrdered;
import org.springframework.stereotype.Component;

/**
 * @author herr05
 */

@Component
public class MyBeanPostProcessor implements BeanPostProcessor, PriorityOrdered {
    //初始化前回调
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("MyBeanPostProcessor-->postProcessBeforeInitialization");
        if (bean instanceof ProcessorDao) {
            System.out.println(beanName);
        }
        return bean;
    }
    //初始化后回调，中间会调用bean的init-method
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("MyBeanPostProcessor-->postProcessAfterInitialization");
        return bean;

    }

    @Override
    public int getOrder() {
        return 0;
    }
}
